//
//  YGHospitalDetailsViewController.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/3/30.
//

#import "YGHospitalDetailsViewController.h"
#import "YGBannerMsgView.h"
#import "YGHomeBLL.h"
#import "YGHospitalDetailModel.h"




@interface YGHospitalDetailsViewController ()

@property(nonatomic, strong)UIScrollView *scrollView;
@property(nonatomic,strong)YGBannerMsgView *bannerMsgView;
@property(nonatomic,strong)UILabel *hospitalIntroduceLable;
@property (nonatomic, strong) YGHospitalDetailModel *model;

@end

@implementation YGHospitalDetailsViewController


#pragma  private
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"医院详情"];
    //设置导航栏属性
    self.navigationController.navigationBar.barTintColor = UIColorFromRGB(0x37C8D7);
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : UIColorFromRGB(0xffffff)}];
    
    
    
    
    [self requestData];
    [self initView];
    [self initcontraints];
    
    
    // Do any additional setup after loading the view.
}


-(void)initView{
    [self.view addSubview:self.scrollView];
    [self.scrollView addSubview:self.bannerMsgView];
    [self.scrollView addSubview:self.hospitalIntroduceLable];
}

-(void)initcontraints{
    
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.bottom.mas_equalTo(self.view);
            
    }];
    
    [self.bannerMsgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.mas_equalTo(self.scrollView);
            make.width.mas_equalTo(self.scrollView.mas_width);
            make.height.mas_equalTo(130);
    }];
    

    
}

//请求医院详情数据
-(void)requestData{
    WeakSelf(self);
    [YGHomeBLL requestHospitalDetailInfoSuccess:^(YGHospitalDetailModel * _Nonnull model) {
        weakself.model=model;
        [weakself configureDataWith:weakself.model];
    } fail:^(NSError * _Nonnull error) {
        
    }];
    
}

-(void)configureDataWith:(YGHospitalDetailModel *)model{
    if (model) {
        
        //医院详情富文本
        NSString *content = model.content;
        self.hospitalIntroduceLable.text=content;
        self.hospitalIntroduceLable.numberOfLines=0;
        self.hospitalIntroduceLable.width = self.view.width - 20;
        self.hospitalIntroduceLable.left = 10;

        [self.bannerMsgView layoutIfNeeded];
//        [self.bannerMsgView setBackgroundColor:UIColorFromRGB(0x37C8D7)];
        _hospitalIntroduceLable.textColor = UIColorFromRGB(0x333333);

        
        self.hospitalIntroduceLable.top = self.bannerMsgView.bottom + 10;
        [self.hospitalIntroduceLable sizeToFit];
        

        
        //计算scrollview的size大小
        self.scrollView.contentSize = CGSizeMake(self.scrollView.width, self.bannerMsgView.height + self.hospitalIntroduceLable.height);
        
        [self.bannerMsgView updateHospitalMsgWith:model];
        
        
       
    }
    
}

#pragma setter
- (UIView *)bannerMsgView{
    if (!_bannerMsgView) {
        _bannerMsgView= [[YGBannerMsgView alloc] init];
        [_bannerMsgView setBackgroundColor:UIColorFromRGB(0x37C8D7)];
        
    }
    return _bannerMsgView;
}

- (UILabel *)hospitalIntroduceLable{
    if (!_hospitalIntroduceLable) {
        _hospitalIntroduceLable= [[UILabel alloc] init];
        _hospitalIntroduceLable.font= [UIFont systemFontOfSize:14];
        _hospitalIntroduceLable.textColor = UIColorFromRGB(0x333333);
        
        
    }
    return _hospitalIntroduceLable;
}

- (UIScrollView *)scrollView{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc]init];
        
    }
    return _scrollView;
}

@end
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


